﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;
using System.IO;

namespace SES.CMS.Module
{
    public partial class ucLeftMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath;
            url = url.Substring(1, url.Length - 1);
            string url1 = url.Replace(".", "/");
            string Module = url1.Substring(0, url1.IndexOf("/"));
            if (Module == "SanPhamChiTiet")
            {
                int sanPhamID = int.Parse(Request.QueryString["ID"].ToString());
                DataTable dtSanPham = new cmsSanPhamBL().SelectBySanPhamID(sanPhamID);
                if (dtSanPham.Rows.Count > 0)
                {
                    int loaiSanPhamID = int.Parse(dtSanPham.Rows[0]["LoaiSanPhamID"].ToString());
                    DataTable dtLSP = new cmsLoaiSanPhamBL().SelectByPK(loaiSanPhamID);
                    if (dtLSP.Rows.Count > 0)
                    {
                        string relationValue = dtLSP.Rows[0]["RelationValue"].ToString();
                        parentRepeaterDataSource(relationValue, 2);
                    }
                }

            }
            else if (Module == "NewProducts" || Module == "Saleoff" || Module == "Search")
            {
                parentRepeater.DataSource = new cmsLoaiSanPhamBL().SelectAllLoaiSanPham_ToLeftMenu(2);
                parentRepeater.DataBind();
            }
            else
            {
                if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    int LoaiSanPhamID = int.Parse(Request.QueryString["ID"]);
                    string relationValue = new cmsLoaiSanPhamBL().SelectByPK(LoaiSanPhamID).Rows[0]["RelationValue"].ToString();
                    parentRepeaterDataSource(relationValue, 2);
                }
            }
        }

        public void parentRepeaterDataSource(string relationValue, int Rootlevel)
        {
            parentRepeater.DataSource = new cmsLoaiSanPhamBL().SelectLoaiSanPham_ToLeftMenu(relationValue, Rootlevel);
            parentRepeater.DataBind();

        }

        public DataTable GetChildData(int ParentID, string relationValue, int Rootlevel)
        {
            return new cmsLoaiSanPhamBL().SelectLoaiSanPham_ToLeftMenuLevel(ParentID, relationValue, Rootlevel);
        }

        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
    }
}